const mysql = require('mysql');

const pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: '123456',
  database: 'test111',
});

const sqlConn = (sql, params) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          console.log('err', err);
          return reject(err);
        }
        connection.query(sql, params, (err, result) => {
          if (err) {
            console.log('err', err);
            return reject(err);
          }
          resolve(result);
          connection.release();
        });
      });
    });
  };

// 导出 sqlConn 函数
module.exports = {
  sqlConn,
};